	$(function () {
		var $mapContend = $('.mapContend');
		//首先遍历数组，得到省份
		var localP_J = [];
		for (var i = 0; i < offlineData.length; i++) {
			if (!localP_J[offlineData[i].province]) {
				localP_J[offlineData[i].province] = [];
				localP_J[offlineData[i].province].push(offlineData[i]);
			} else {
				localP_J[offlineData[i].province].push(offlineData[i]);
			}
		}
		var siData = [];
		for (var i in localP_J) {
			var obj = {
				name: i,
				data: localP_J[i]
			}
			siData.push(obj);
		}
	

		//给地址寻找下拉框添加值
		//     var simulationData = [{
		//         name: "广东省",
		//         data: offlineData
		//     }]
		// 	console.log(offlineData);
		// 
		var simulationData = siData;
		
		var civilOrOffice = '民用'; //判断当前是民用还是办公模块
		if ($("#module1210").size() > 0) {
			civilOrOffice = '办公';
		} else {
			civilOrOffice = '民用';
		}
		// var simulationData = [{
		// 	name: "广东省",
		// 	data: offlineData
		// }]
		var province = document.getElementById("province");
		var ocity = document.getElementById("city");
		var oshop = document.getElementById("shop");
		var positionCenter = [113.422060021, 22.5451775145];
		var localProvince = [];
		var localArr = [];
		var arr_province = []; //省
		var arr_city = []; //市区
		var currentSelectProvince; //当前选择的省
		var currentSelectCity; //当前选择的市

		simulationData.forEach(function (item, index) {
			localProvince[item.name] = item.data;
			localProvince[item.name].forEach(function (item2) {
				localArr[item2.city] = item2.shop_info;
			})
		})
		console.log(localArr)
		$.each($mapContend, function (index, item) {
			var mapType = $(item).attr('mapType');
			var str = '<div class="shopleft">';
			str += '<div class="par">';
			str += '<select id="province" class="form-control-select provinceB">';
			str += '<option value="">-请选择-</option>';
			str += '</select>';
			str += '<select id="city" class="form-control-select cityB">';
			str += '<option value="">-请选择-</option>';
			str += '</select>';
			str += '<select id="shop" class="form-control-select shopB">'
			str += '<option value="">-请选择-</option>';
			str += '</select>';
			str += '</div>';
			str += '<div class="infoList">';
			str += '<p>地址:&nbsp;<i id="shopinfo_address" class="shopinfo_address"></i></p>';
			str += '<p>电话：&nbsp;<i id="shopinfo_phone" class="shopinfo_phone"></i></p>';
			str += '<p>营业时间:&nbsp;<i id="shopinfo_time" class="shopinfo_time"></i></p>';
			str += '</div>';
			str += '</div>';
			str += '<div class="mapRigth">';
			str += '<div class="containerMap" id="containerMap' + index + '">' + '</div>';
			str += '</div>';
			$(item).append(str);

			var provinceB = $(item).find(".provinceB");
			var cityB = $(item).find(".cityB");
			var shopB = $(item).find(".shopB");
			var infoList = $(item).find(".infoList");
			var shopinfo_address = $(infoList).find(".shopinfo_address");
			var shopinfo_phone = $(infoList).find(".shopinfo_phone");
			var shopinfo_time = $(infoList).find(".shopinfo_time");
			var idMap = 'containerMap' + index;
			var shopInfoSize = $(item).attr('shopInfoSize');
			var shopInfoColor = $(item).attr('shopInfoColor');

			$(infoList).css("color", shopInfoColor);
			$(infoList).css("font-size", shopInfoSize);
			console.log(idMap);
			//先初初始化地图
			var ishasMap = document.getElementById(idMap);
			if (ishasMap) {
				var map = new AMap.Map(idMap, {
					resizeEnable: true,
					center: positionCenter,
					zoom: 13
				});
				map.clearMap(); // 清除地图覆盖物
				offlineData.forEach(function (item) {
					if (item.shop_info) {
						item.shop_info.forEach(function (item2) {
							var marker = new AMap.Marker({
								map: map,
								icon: item2.icon,
								position: [item2.position[0], item2.position[1]],
								offset: new AMap.Pixel(-12, -36)
							});
							marker.setTitle(item2.title);
							// 设置label标签
							marker.setLabel({ //label默认蓝框白底左上角显示，样式className为：amap-marker-label
								offset: new AMap.Pixel(20, 20), //修改label相对于maker的位置
								content: item2.title
							});
						})
					}
				})
				var center = map.getCenter();
				var centerText = '当前中心点坐标：' + center.getLng() + ',' + center.getLat();

			}

			//先给省份赋值
			for (var i = 0; i < simulationData.length; i++) { //下拉栏内的元素来源于数组中的元素，遍历数组
				var option = new Option(simulationData[i].name, simulationData[i].name); //创建Option对象（这个O要大写），存入值
				if ($(provinceB)) {
					$(provinceB).append(option); //把option添加到event对象的末尾
				}

			}
			//绑定省份点击事件
			$(provinceB).bind("change", function () {
				var val = $(this).children('option:selected').val();
				currentSelectProvince = val;
				var getType = mapType;
				if (localProvince[val]) {
					var city = [];
					localProvince[val].forEach(function (item, index) {
						city.push(item);
					})
					$(cityB).empty();
					$(shopB).empty();
					$(cityB).append(new Option('请选择', '请选择'));
					city.forEach(function (item2, index2) {
						var option = new Option(item2.city, item2.city); //创建Option对象（这个O要大写），存入值

						var isHasTypeShop = true;
						var civilOrOfficeIndex = 0;
						item2.shop_info.forEach(function (te, ti) {
							if (te.type == civilOrOffice) {
								++civilOrOfficeIndex;
							}
						})
						if (civilOrOfficeIndex != 0) {
							$(cityB).append(option);
							$(shopB).append(new Option('请选择', '请选择'));
							if (index2 == 0) {
								
							
							item2.shop_info.forEach(function (item3, index3) {
								if (item3.type == getType) {
									var option2 = new Option(item3.title, item3.title); //创建Option对象（这个O要大写），存入值	
									$(shopB).append(option2);
								}
							})
							}
						}
					})
				}
			})

			//绑定市区下拉框点击事件
			$(cityB).bind("change", function () {
				var getType = mapType;
				var val = $(provinceB).children('option:selected').val();
				var cityText = $(this).children('option:selected').val();
				currentSelectCity = cityText;
				if (localProvince[val]) {
					var city = [];
					localProvince[val].forEach(function (item, index) {
						city.push(item);
					})
					$(shopB).empty();
					city.forEach(function (item2, index2) {
						if (cityText == item2.city) {
							$(shopB).append(new Option('请选择', '请选择'));
							item2.shop_info.forEach(function (item3, index3) {
								if (item3.type == getType) {
									var option2 = new Option(item3.title, item3.title); //创建Option对象（这个O要大写），存入值	
									$(shopB).append(option2);
								}
							})
						}
					})
				}
			})

			//绑定门店点击事件
			$(shopB).bind("change", function () {
				var index = $(this).children('option:selected').val();
				var shopText = index;
				console.log(currentSelectCity)
				console.log(localArr[currentSelectCity]);
				if (localArr[currentSelectCity]) {
					localArr[currentSelectCity].forEach(function (item, index) {
						if (shopText == item.title && mapType == item.type) {
							positionCenter = item['position'];
							shopChangeMapAjax(item, idMap);
							$(infoList).show();
							$(shopinfo_address).html(item.address);
							$(shopinfo_phone).html(item.tel);
							$(shopinfo_time).html(item.service_time);
						}
						console.log(index);
					})
				}
			})

		});

		$($mapContend).trigger("create");

		function shopChangeMapAjax(item, idstr) {
			var map = new AMap.Map(idstr, {
				resizeEnable: true,
				center: item.position,
				zoom: 13
			});
			map.clearMap(); // 清除地图覆盖物
			var marker = new AMap.Marker({
				map: map,
				icon: item.icon,
				position: [item.position[0], item.position[1]],
				offset: new AMap.Pixel(-12, -36)
			});
			marker.setTitle(item.title);
			// 设置label标签
			marker.setLabel({ //label默认蓝框白底左上角显示，样式className为：amap-marker-label
				offset: new AMap.Pixel(20, 20), //修改label相对于maker的位置
				content: item.title
			});
		}

		function ajaxMap(arr) {
			var map = new AMap.Map('containerMap', {
				resizeEnable: true,
				center: arr[0].position,
				zoom: 13
			});
			map.clearMap(); // 清除地图覆盖物
			arr.forEach(function (item) {
				var marker = new AMap.Marker({
					map: map,
					icon: item.icon,
					position: [item.position[0], item.position[1]],
					offset: new AMap.Pixel(-12, -36)
				});
				marker.setTitle(item.title);
				// 设置label标签
				marker.setLabel({ //label默认蓝框白底左上角显示，样式className为：amap-marker-label
					offset: new AMap.Pixel(20, 20), //修改label相对于maker的位置
					content: item.title
				});

			})
			var center = map.getCenter();
			var centerText = '当前中心点坐标：' + center.getLng() + ',' + center.getLat();

		}

	})
